/*
	File:    	CarPlayControlClient.h
	Package: 	Apple CarPlay Communication Plug-in.
	Abstract: 	n/a 
	Version: 	450.14
	
	Disclaimer: IMPORTANT: This Apple software is supplied to you, by Apple Inc. ("Apple"), in your
	capacity as a current, and in good standing, Licensee in the MFi Licensing Program. Use of this
	Apple software is governed by and subject to the terms and conditions of your MFi License,
	including, but not limited to, the restrictions specified in the provision entitled ”Public
	Software”, and is further subject to your agreement to the following additional terms, and your
	agreement that the use, installation, modification or redistribution of this Apple software
	constitutes acceptance of these additional terms. If you do not agree with these additional terms,
	please do not use, install, modify or redistribute this Apple software.
	
	Subject to all of these terms and in consideration of your agreement to abide by them, Apple grants
	you, for as long as you are a current and in good-standing MFi Licensee, a personal, non-exclusive 
	license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, 
	reproduce, and modify the Apple Software in source form, and to use, reproduce, modify, and 
	redistribute the Apple Software, with or without modifications, in binary form. While you may not 
	redistribute the Apple Software in source form, should you redistribute the Apple Software in binary
	form, you must retain this notice and the following text and disclaimers in all such redistributions
	of the Apple Software. Neither the name, trademarks, service marks, or logos of Apple Inc. may be
	used to endorse or promote products derived from the Apple Software without specific prior written
	permission from Apple. Except as expressly stated in this notice, no other rights or licenses, 
	express or implied, are granted by Apple herein, including but not limited to any patent rights that
	may be infringed by your derivative works or by other works in which the Apple Software may be 
	incorporated.  
	
	Unless you explicitly state otherwise, if you provide any ideas, suggestions, recommendations, bug 
	fixes or enhancements to Apple in connection with this software (“Feedback”), you hereby grant to
	Apple a non-exclusive, fully paid-up, perpetual, irrevocable, worldwide license to make, use, 
	reproduce, incorporate, modify, display, perform, sell, make or have made derivative works of,
	distribute (directly or indirectly) and sublicense, such Feedback in connection with Apple products 
	and services. Providing this Feedback is voluntary, but if you do provide Feedback to Apple, you 
	acknowledge and agree that Apple may exercise the license granted above without the payment of 
	royalties or further consideration to Participant.
	
	The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR 
	IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY 
	AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR
	IN COMBINATION WITH YOUR PRODUCTS.
	
	IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES 
	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
	PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION 
	AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
	(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 
	POSSIBILITY OF SUCH DAMAGE.
	
	Copyright (C) 2014-2015 Apple Inc. All Rights Reserved. Not to be used or disclosed without permission from Apple.
*/

#ifndef	__CarPlayControlClient_h__
#define	__CarPlayControlClient_h__

#include "CFUtils.h"
#include "CommonServices.h"
#include "DebugServices.h"
#include "AirPlayReceiverServer.h"

#ifdef __cplusplus
extern "C" {
#endif

//---------------------------------------------------------------------------------------------------------------------------
/*!	@group		CarPlayControlClient
	@abstract	Async CarPlayControl client for CarPlay Receivers.
*/

typedef const struct CarPlayControlClient *		CarPlayControlClientRef;	// CFType
typedef const struct CarPlayController *		CarPlayControllerRef;		// CFType
	
CFTypeID	CarPlayControlClientGetTypeID( void );
CFTypeID	CarPlayControllerGetTypeID( void );


//---------------------------------------------------------------------------------------------------------------------------
/*!	@enum		CarPlayControlClientEvent
	@abstract	Event constants for CarPlayControlClientCallback
 
	@constant	kCarPlayControlClientEvent_AddOrUpdateController
					Controller was added or updated (e.g. its name changed).
					Event info is the new or updated CarPlayControllerRef instance.
	@constant	kCarPlayControlClientEvent_RemoveController
					Controller was removed.
					Event info is the affected CarPlayControllerRef instance
	@constant	kCarPlayControlClientEvent_Stopped
					CarPlayControlClient instance was stopped.
					Event info is a pointer to an OSStatus value that will indicate if the stop was due to an error.
*/

enum
{
	kCarPlayControlClientEvent_AddOrUpdateController	= 0,
	kCarPlayControlClientEvent_RemoveController			= 1,
	kCarPlayControlClientEvent_Stopped					= 2,
};
typedef uint32_t CarPlayControlClientEvent;

#define CarPlayControlEventToString( X )	( \
	( (X) == kCarPlayControlClientEvent_AddOrUpdateController )	? "Add/Update"	: \
	( (X) == kCarPlayControlClientEvent_RemoveController )		? "Remove"		: \
	( (X) == kCarPlayControlClientEvent_Stopped )				? "Stopped"		: \
																  "UNKNOWN" )
typedef void
	( *CarPlayControlClientCallback )(
		CarPlayControlClientRef		inClient,
		CarPlayControlClientEvent	inEvent,
		void *						inEventInfo,
		void *						inContext );

OSStatus
	CarPlayControlClientCreateWithServer(
		CarPlayControlClientRef *		outClient,
		AirPlayReceiverServerRef		inServer,
		CarPlayControlClientCallback	inCallback,
		void *							inContext );

OSStatus	CarPlayControlClientStart( CarPlayControlClientRef inClient );
OSStatus	CarPlayControlClientStop( CarPlayControlClientRef inClient );
OSStatus	CarPlayControlClientConnect( CarPlayControlClientRef inClient, CarPlayControllerRef inController, uint16_t vid, uint16_t pid );
OSStatus	CarPlayControlClientModesChanged( );
OSStatus	CarPlayControlClientCheckAudioStream( int inType, uint64_t * outConnectionID);
OSStatus	CarPlayControlClientDisconnect( CarPlayControlClientRef inClient, CarPlayControllerRef inController );

OSStatus	CarPlayControllerCopyName( CarPlayControllerRef inController, CFStringRef *outName );
OSStatus	CarPlayControllerGetBluetoothMacAddress( CarPlayControllerRef inController, uint8_t outAddress[ 6 ] );
OSStatus	CarPlayControllerCopySourceVersion( CarPlayControllerRef inController, CFStringRef *outSourceVersion );
OSStatus    CarPlayControllerGetInterfaceName( CarPlayControllerRef inController, CFStringRef *outName );
OSStatus	CarPlayControllerGetServicesCount( CarPlayControllerRef inController, CFIndex * outCount );
	
OSStatus	CarPlayControlClientSTALeft( CarPlayControlClientRef inClient, CarPlayControllerRef inController, const char *inIPAddress );

OSStatus	CarPlayControlClientBack2Home( );
OSStatus	CarPlayControlClientUnduckAudio( );
OSStatus	CarPlayControlClientTearDownAudio( );
OSStatus	CarPlayControlClientModesChangedAudio( );
OSStatus	CarPlayControlClientAudioStart( );
OSStatus	CarPlayControlClientAudioStop( );

typedef void
	( *CarPlayControlClientSharkHttpEvent_f )(
		int 						event);

typedef struct
{
	void *									context;			// Context pointer for the delegate to use.
	void *									context2;			// Extra context pointer for the delegate to use.
	CarPlayControlClientSharkHttpEvent_f			shark_httpEvent_f;	// Function to call when need to request car side auth

}	CarPlayControlClientDelegate;

#define CarPlayControlClientDelegateInit( PTR )	memset( (PTR), 0, sizeof( CarPlayControlClientDelegate ) );
//! @endgroup

#define SHARK_EVENT_PAIR_SETUP   100
#define SHARK_EVENT_PAIR_SETUP1  101
#define SHARK_EVENT_PAIR_SETUP2  102
#define SHARK_EVENT_PAIR_SETUP3  103

#define SHARK_EVENT_PAIR_VERIFY1  110
#define SHARK_EVENT_PAIR_VERIFY2  111

#define SHARK_EVENT_PAIR_AUTH_SETUP  115
#define SHARK_EVENT_RTSP_OPTIONS  116
#define SHARK_EVENT_SESSION_SETUP  117
#define SHARK_EVENT_SESSION_GET_INFO  118
#define SHARK_EVENT_SESSION_REQUEST_CONNECT_EVENT  119
#define SHARK_EVENT_SESSION_RECORD  120
#define SHARK_EVENT_SESSION_SCREEN_TIMING  121
#define SHARK_EVENT_SESSION_SCREEN_START  122
#define SHARK_EVENT_SESSION_SCREEN_STOP  123
#define SHARK_EVENT_SESSION_FEEDBACK  124
#define SHARK_EVENT_SESSION_POST_COMMAND_ModesInit  125
#define SHARK_EVENT_SESSION_POST_COMMAND  126
#define SHARK_EVENT_SESSION_POST_CMD_DISABLE_BLUETOOTH  127
#define SHARK_EVENT_SESSION_AUDIO_START  128
#define SHARK_EVENT_SESSION_AUDIO_STOP  129
#define SHARK_EVENT_SESSION_MODES_CHANGED  130
#define SHARK_EVENT_SESSION_MODES_CHANGED_TEARDOWN  131
#define SHARK_EVENT_SESSION_BACK_HOME  132
#define SHARK_EVENT_SESSION_TEARDOWN_SCREEN  133
#define SHARK_EVENT_SESSION_RESUME_SCREEN 134
#define SHARK_EVENT_SESSION_AUDIO_SETUP_CHANNEL 135
#define SHARK_EVENT_SESSION_TEARDOWN_AUDIO  136
#define SHARK_EVENT_SESSION_MODES_CHANGED_AUDIO  137
#define SHARK_EVENT_SESSION_MODES_DUCK_AUDIO  138
#define SHARK_EVENT_SESSION_MODES_UNDUCK_AUDIO  139
#define SHARK_EVENT_SESSION_HOMEKIT_DISABLE  140
#define SHARK_EVENT_SESSION_POST_CMD_CHANGE_UI_CONTEXT  141
#define SHARK_EVENT_SESSION_POST_AUDIO_FOCUS_CHANGED  142
#define SHARK_EVENT_SESSION_POST_AUDIO_FOCUS_GAIN  143
#define SHARK_EVENT_SESSION_POST_AUDIO_FOCUS_LOST  144
#define SHARK_EVENT_SESSION_POST_VIEW_AREA_INDEX   145
#define SHARK_EVENT_SESSION_POST_UPDATE_VIEW_AREA   146



#define AUDIO_CHANNEL_STOP 			0
#define AUDIO_CHANNEL_MEDIA 		1
#define AUDIO_CHANNEL_PHONE 		2
#define AUDIO_CHANNEL_SPEECH 		3
#define AUDIO_CHANNEL_NAVIGATION 	4

#ifdef __cplusplus
}
#endif

#endif // __CarPlayControlClient_h__
